package com.example.coffeeseller_2.model.helper.view_helper;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import com.example.coffeeseller_2.R;
import com.example.coffeeseller_2.model.beans.Coffee;
import com.example.coffeeseller_2.model.beans.Step;
import com.example.coffeeseller_2.model.beans.TasteInfo;
import com.example.coffeeseller_2.model.listenner.OnQubeimaSureListenner;
import com.example.coffeeseller_2.model.listenner.OnTasteSelectedListenner;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by WH on 2018/10/12.
 * 取杯码口味选择辅助类
 */

public class QuebiemaTasteViewHelper implements View.OnClickListener {
    private static String TAG = "QuebiemaTasteViewHelper";
    private View view;
    private LinearLayout mTasteContainer;
    private LinearLayout mSure;
    private Context context;
    private Coffee coffee;
    private OnTasteSelectedListenner onTasteSelectedListenner;
    private OnQubeimaSureListenner onQubeimaSureListenner;
    private List<TasteHelper> tasteHelpers;


    public QuebiemaTasteViewHelper(Context context) {

        this.context = context;
        view = LayoutInflater.from(context).inflate(R.layout.include_qubeima_taste_choose, null, false);
        bindViews();
        initData();
    }

    private void initData() {
        tasteHelpers = new ArrayList<>();
    }

    private void bindViews() {
        mTasteContainer = (LinearLayout) view.findViewById(R.id.tasteContainer);
        mSure = (LinearLayout) view.findViewById(R.id.sure);
        mSure.setOnClickListener(this);
    }

    public View getView() {
        return view;
    }

    public void setDate(Coffee coffee, OnTasteSelectedListenner onTasteSelectedListenner
            , OnQubeimaSureListenner onQubeimaSureListenner) {
        this.coffee = coffee;
        this.onTasteSelectedListenner = onTasteSelectedListenner;
        this.onQubeimaSureListenner = onQubeimaSureListenner;
        mTasteContainer.removeAllViews();
    }

    /*
 * 添加口味布局
 * */
    public void addToTasteContainer(TasteInfo tasteInfo) {

        if (coffee == null || coffee.getStepList() == null) {
            return;
        }
        List<Step> steps = coffee.getStepList();
        if (steps.size() <= 0) {
            return;
        }
        if (tasteInfo.getTastes()==null || tasteInfo.getTastes().size()<=0){

            Log.d(TAG, "tasteInfo.getTastes()==null || tasteInfo.getTastes().size()<=0");

            return;
        }

        Log.d(TAG, "getTastes size = " +  tasteInfo.getTastes().size() + "");
        TasteHelper tasteHelper = new TasteHelper(context, tasteInfo, coffee, onTasteSelectedListenner);
        tasteHelpers.add(tasteHelper);
        mTasteContainer.addView(tasteHelper.getView());
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.sure:
                //跳转制作页面
                if (onQubeimaSureListenner != null) {
                    onQubeimaSureListenner.qubeimaSureClick();
                }
                break;
        }
    }

}
